package cn.cmcc.intertelecom.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.cmcc.intertelecom.bean.Dictionary;
import cn.cmcc.intertelecom.bean.DictionaryExample;
import cn.cmcc.intertelecom.bean.DictionaryExample.Criteria;
import cn.cmcc.intertelecom.bean.DictionaryType;
import cn.cmcc.intertelecom.dao.DictionaryMapper;

@Service
public class DictionaryService {
	@Autowired
	private DictionaryMapper dictionaryMapper;

	/**
	 * 获取所以的字典以及其 类型
	 * @return
	 */
	public List<Dictionary> selectAllWithType() {
		
		DictionaryExample example=new DictionaryExample();
		example.setOrderByClause("id");
		return dictionaryMapper.selectByExampleWithType(example);
	}

	/**
	 * 根据已知的条件获取 字典及其类型
	 * @param dictionary
	 * @return
	 */
	public List<Dictionary> selectAllWithType(Dictionary dictionary) {
		
		DictionaryExample example=new DictionaryExample();
		Criteria criteria = example.createCriteria();
		if(dictionary.getDictionaryName() !=null && !dictionary.getDictionaryName().equals("")){
			criteria.andDictionaryNameEqualTo(dictionary.getDictionaryName());
		}
		if(dictionary.getTypeId() !=null && !dictionary.getTypeId().equals("")){
			criteria.andTypeIdEqualTo(dictionary.getTypeId());
		}
		if(dictionary.getDictionaryRemark() !=null && !dictionary.getDictionaryRemark().equals("")){
			criteria.andDictionaryRemarkEqualTo(dictionary.getDictionaryRemark());
		}
		return dictionaryMapper.selectByExampleWithType(example);
	}

	/**
	 * 根据id获取字典的内容  不包括类型
	 * @param id
	 * @return
	 */
	public Dictionary selectById(Integer id) {
	
		return dictionaryMapper.selectByPrimaryKey(id);
	}

	/**
	 * 根据字典id更新字典
	 * @param dictionary
	 */
	public void updateById(Dictionary dictionary) {
		dictionaryMapper.updateByPrimaryKey(dictionary);
		
	}

	/**
	 * 新建字典
	 * @param dictionary
	 */
	public void insertDContent(Dictionary dictionary) {
		dictionaryMapper.insert(dictionary);
		
	}

	/**
	 * 删除一条字典
	 * @param parseInt
	 */
	public void deleteDept(int id) {
		dictionaryMapper.deleteByPrimaryKey(id);
		
	}

	/**
	 * 
	 * 批量删除 一组 记录
	 * @param ids
	 */
	public void deleteBatch(List<Integer> ids) {
		DictionaryExample example=new DictionaryExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(ids);
		dictionaryMapper.deleteByExample(example);
		
	}

	

	

	
}
